<?php
/**
 *   Kaltura Browser - components/com_kaltura/views/details/tmpl/default.php
 *   Author: Miguel Puig García (miguel@bittingbits.com)
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2011 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
function iOSDetect() {
   $browser = strtolower($_SERVER['HTTP_USER_AGENT']); // Checks the user agent
   if(strstr($browser, 'iphone') || strstr($browser, 'ipod') || strstr($browser, 'ipad')) {
      $mobileios = true;
   } else { $mobileios = false; }	
   return($mobileios);
}

function formatMilliseconds($milliseconds) {
    $seconds = floor($milliseconds / 1000);
    $minutes = floor($seconds / 60);
    $hours = floor($minutes / 60);
    $milliseconds = $milliseconds % 1000;
    $seconds = $seconds % 60;
    $minutes = $minutes % 60;

    $format = '%u:%02u:%02u';
    $time = sprintf($format, $hours, $minutes, $seconds, $milliseconds);
    return rtrim($time, '0');
}
 
iOSDetect();

?>

<div class="video_box_container">
	
	<div class="video_container">
		<?php if(iOSDetect()): ?>
		
			<video controls width="400" poster="http://d3j7fvo3smrw3r.cloudfront.net/p/100/sp/10000/thumbnail/entry_id/<?php echo $this->item->id;?>/width/120/height/90/bgcolor/000000/type/2">
				<source src="http://streamservice.eurotvguild.com/flvclipper/entry_id/<?php echo $this->item->id;?>/a.mp4" type="video/mp4" />
			</video>
		
		<?php else: ?>
		
		<object id="kaltura_player_1311932423" name="kaltura_player_1311932423" type="application/x-shockwave-flash" allowFullScreen="true" allowNetworking="all" allowScriptAccess="always" height="333" width="400" bgcolor="#000000" xmlns:dc="http://purl.org/dc/terms/" xmlns:media="http://search.yahoo.com/searchmonkey/media/" rel="media:video" resource="<?php echo $this->meta->kalturaurl;?>/index.php/kwidget/cache_st/1311932423/wid/_100/uiconf_id/4421494/entry_id/<?php echo $this->item->id;?>" data="<?php echo $this->meta->kalturaurl;?>/index.php/kwidget/cache_st/1311932423/wid/_100/uiconf_id/4421494/entry_id/<?php echo $this->item->id;?>"><param name="allowFullScreen" value="true" /><param name="allowNetworking" value="all" /><param name="allowScriptAccess" value="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="&{FLAVOR}" /><param name="movie" value="<?php echo $this->meta->kalturaurl;?>/index.php/kwidget/cache_st/1311932423/wid/_100/uiconf_id/4421494/entry_id/<?php echo $this->item->id;?>" /><a href="http://corp.kaltura.com">video platform</a> <a href="http://corp.kaltura.com/video_platform/video_management">video management</a> <a href="http://corp.kaltura.com/solutions/video_solution">video solutions</a> <a href="http://corp.kaltura.com/video_platform/video_publishing">video player</a> <a rel="media:thumbnail" href="http://d3j7fvo3smrw3r.cloudfront.net/p/100/sp/10000/thumbnail/entry_id/<?php echo $this->item->id;?>/width/120/height/90/bgcolor/000000/type/2"></a> <span property="dc:description" content="In this programme, Richard Bandler models four immensely successful people whom you will learn from, be inspired by - and whose skills you will be able to use in your own life."></span><span property="media:title" content="The Secrets of Success - Aldo Zilli"></span> <span property="media:width" content="400"></span><span property="media:height" content="333"></span> <span property="media:type" content="application/x-shockwave-flash"></span> </object>
		
		<?php endif; ?>
	</div>
	
	
	<div class="info_container">
	<div class="free_html_area">
	    <a href="http://www.freeband.tv/index.php?option=com_jforms&view=form&id=1">
	        <img src="http://www.freeband.tv/images/sales_inquiries.png" alt="Sales Inquires" />
	    </a>
	</div>
	<?php if(isset($this->item->id)): ?>
		<h1><?php echo $this->item->name; ?></h1>
		<div class="info_created">
		<span>Created: </span>
		<?php 
			$jdate = new JDate($this->item->created_at);
			echo $jdate->toFormat('%d %b %Y');
		?>
		</div>
		
		<div class="info_msecs">
		<span>Length:</span> 
		<?php 
echo formatMilliseconds($this->item->length_in_msecs);
		?>
		</div>
		<?php foreach ($this->fields as $field) {
		    $val = $this->kaltura->getFieldValue($field->id);
		    if ($val) {
		?>
		        <div class="custom_field">
		            <span><?php echo $field->field_name; ?>: </span>
		            <?php echo $val->value; ?>
		        </div>    
		<?php } } ?>
		<div class="info_description"><?php echo $this->item->description; ?></div>
		
	<?php else: ?>
	
	Invalid Video
	<?php endif; /* i hate these things miguel... you could use '{' and '}' as whole world. */ ?> 
	</div>
	
	<div class="clear"></div>

</div>

